package com.example.android_mvp_one.mvp.presenter;

import com.example.android_mvp_one.mvp.control.LreControl;
import com.example.android_mvp_one.mvp.model.entity.BaseEntitiy;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

@ActivityScope
public class LruPresenter extends BasePresenter<LreControl.LruControlModel, LreControl.LruControlView> {

    @Inject
    public LruPresenter(LreControl.LruControlModel model, LreControl.LruControlView rootView) {
        super(model, rootView);
    }

    public void postNetWork() {

        mModel.postNewWork().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<BaseEntitiy>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    }
                    @Override
                    public void onNext(BaseEntitiy entitiy) {

                        if( entitiy == null) {
                            mRootView.showMessage( "Net Data is null" );
                            return;
                        }

                        mRootView.onSucceed( entitiy);
                    }
                    @Override
                    public void onError(Throwable e) {
                        mRootView.showMessage( e.getMessage());
                    }
                    @Override
                    public void onComplete() {

                    }
                });
    }
}
